import { currentDates, time, timeBefter } from '../../utils/util'
const app = getApp()
Page({
  data: { imgurl: app.globalData.imgurl, remark: '' },
  onLoad({ o_id }) {
    this._getData(o_id)
    this.setData({
      o_id,
    })
  },
  async _getData(o_id) {
    let { code, data } = await wx.requestAsync({
      url: '/order/detail',
      data: {
        o_id,
      },
    })
    if (code == 0) {
      if (data.spell.begin_at) {
        let date = (data.spell.begin_at =
          currentDates(data.spell.begin_at * 1000) +
          ' ' +
          time(data.spell.begin_at) +
          '-' +
          time(data.spell.end_at))
        this.setData({
          date,
        })
        console.log(1)
      } else {
        let date =
          currentDates(data.parent.pre_at * 1000) +
          ' ' +
          time(data.parent.pre_at) +
          '-' +
          timeBefter(data.parent.pre_at, data.parent.hour)
        this.setData({
          date,
        })
      }
      this.setData(data)
    }
  },
  onChangeRemark({ detail }) {
    this.setData({ remark: detail })
  },
  // 确认提交
  async submit() {
    let { o_id, remark } = this.data
    let { code } = await wx.requestAsync({
      url: '/order/refund',
      data: {
        o_id,
        remark,
      },
    })
    if (code == 0) {
      wx.showToast({
        title: '退款成功',
        icon: 'none',
        duration: 2000,
        success: function () {
          setTimeout(function () {
            //要延时执行的代码
            wx.navigateTo({
              url: '/pages/appointment/appointment',
            })
          }, 1000) //延迟时间
        },
      })
    }
  },
})
